package com.sntk.organauthomanager.infrastructure.validation;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: Validation
 * @author: wgchao
 * @createTime: 2020/7/14 11:31 AM
 * @Description: TODO
 */
public class Validation {
    public static List<?> getValidation(BindingResult result) {
        List<String> resultList = new ArrayList<>();
        if(result.hasFieldErrors()){
            List<FieldError> errorList = result.getFieldErrors();
            errorList.forEach(item -> resultList.add(item.getField()+" "+item.getDefaultMessage()));
        }
        return resultList;
    }
}
